import 'package:flutter/cupertino.dart';
import '../pages/LoginPage.dart';

class RotaTranPageState extends State<RotaTranPage>
    with TickerProviderStateMixin {
  RotaTranPageState({this.onPressed});
  final UDPressCallBack? onPressed;

  /// 手动控制动画的控制器
  late final AnimationController _manualController;

  /// 手动控制
  late final Animation<double> _manualAnimation;

  @override
  void initState() {
    super.initState();

    /// 不设置重复，使用代码控制进度，动画时间1秒
    _manualController = AnimationController(
      vsync: this,
      duration: const Duration(milliseconds: 500),
    );
    _manualAnimation =
        Tween<double>(begin: 0, end: 1).animate(_manualController);
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: RotationTransition(
        turns: _manualAnimation,
        child: CupertinoButton(
          onPressed: () {
            /// 获取动画当前的值
            var value = _manualController.value;

            /// 0.5代表 180弧度
            if (value == 0.5) {
              _manualController.animateTo(0);
              onPressed?.call(false);
            } else {
              _manualController.animateTo(0.5);
              onPressed?.call(true);
            }
          },
          child: const Image(
              height: 15,
              width: 15,
              image: AssetImage('assets/icon/icon_up1.png')),
        ),
      ),
    );
  }
}

///点击密码列表的按钮回调
typedef UDPressCallBack = void Function(bool result);